import axios from '../config.js';

// 商城首页数据获取
const mallList = (data) => {
  return axios({
    url: 'admin/shop/product/saleLst',
    method: 'post',
    data,
  });
};

// 封装包含上传内容的方法
// @url:上传地址
// @data:上传数据
function upload(url, data = {}) {
  return new Promise((res, rej) => {
    let form = new FormData();
    for (var key in data) {
      // append:向表单实例添加数据的方法
      // key: 数据的名称
      // value: 数据的值
      form.append(key, data[key]);
    }
    axios({
      method: 'post',
      url,
      data: form,
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }).then(data => {
      res(data)
    }).catch(err => {
      rej(err)
    })
  })
}

export default {
  mallList,
  upload
}